package com.example.yimai.controller;

import com.example.yimai.entity.ProductCategory;
import com.example.yimai.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @GetMapping("/all")
    public List<ProductCategory> getAllCategory(){
        return productCategoryService.getAll();
    }

    @GetMapping("/top")
    public List<ProductCategory> getTopCategory(){
        return productCategoryService.getTop();
    }

    @GetMapping("/child/{id}")
    public List<ProductCategory> getChildCategory(@PathVariable int id){
        return productCategoryService.getChild(id);
    }

    @GetMapping("/get/{id}")
    public ProductCategory getCategory(@PathVariable String id){
        return productCategoryService.getCategory(id);
    }

    @PutMapping("/update")
    public String updateCategory(@RequestParam Map<String,Object> params){
        return productCategoryService.updateCategory(params);
    }

    @PostMapping("/add")
    public String addCategory(@RequestParam Map<String,Object> params){
        return productCategoryService.addCategory(params);
    }

    @DeleteMapping("/delete")
    public String deleteCategory(@RequestParam Integer id){
        return productCategoryService.deleteCategory(id);
    }

}
